package com.zj.core.view

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.widget.ScrollView

/**
 * Created by Administrator on 2019/5/30.
 */

class MyScrollView : ScrollView {
    private val mCurrentMoveY = 0f
    private val mProMoveY = 0f

    constructor(context: Context) : super(context) {}

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {}

    override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
        return super.dispatchTouchEvent(ev)
    }

    override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
        return super.onInterceptTouchEvent(ev)
    }

    override fun onTouchEvent(ev: MotionEvent): Boolean {
        //        switch (ev.getAction()) {
        //            case MotionEvent.ACTION_DOWN: {
        //                mProMoveY = ev.getY();
        //            }
        //            break;
        //            case MotionEvent.ACTION_MOVE: {
        //                mCurrentMoveY = ev.getY();
        //                this.scrollBy(0, (int) (mProMoveY - mCurrentMoveY));
        //                mProMoveY = mCurrentMoveY;
        //            }
        //            break;
        //            case MotionEvent.ACTION_UP: {
        //            }
        //            break;
        //        }
        //        if (canScroll()) {
        //            return true;
        //        } else {
        //            return false;
        //        }
        return super.onTouchEvent(ev)
    }

    /**
     * 判断TextScrollView里面包裹的内容是否可以滚动
     *
     * @return
     */
    private fun canScroll(): Boolean {
        val childAt = getChildAt(0)
        if (childAt != null) {
            val height = childAt.height
            return getHeight() < height
        }
        return false
    }
}